import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 导入view ui
import ViewUI from 'view-design'
import 'view-design/dist/styles/iview.css'
// 引入全局scss
import './styles/layout.scss'
import './styles/public.scss'

// --------------引入svg图标-----------------
import './assets/iconfont/iconfont.css'


import { setRemUnit } from './utils/rem';

// 首次加载时设置根元素字体大小
setRemUnit();

// 监听窗口大小变化事件，重新设置根元素字体大小
// window.addEventListener('resize', setRemUnit);
// window.addEventListener('orientationchange', setRemUnit);

// 注册view ui
Vue.use(ViewUI, {
    capture: false
})

let instance = null
function render (props = {}) {
    const { container } = props
    instance = new Vue({
        router,
        store,
        render: (h) => h(App)
    }).$mount(container ? container.querySelector('#app') : '#app') // 为了避免根id#app与其他DOM冲突，需要限制查找范围
}

if (window.__POWERED_BY_QIANKUN__) {
    __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
}
if (!window.__POWERED_BY_QIANKUN__) {
    render()
}

// --------- 生命周期函数------------//
export async function bootstrap () {}
export async function mount (props) {
    props.onGlobalStateChange((state, prev) => {
        console.log(state, prev)
    })
    props.setGlobalState(store.getters.userinfo)
    render(props)
}
export async function unmount () {
    instance.$destroy()
    instance.$el.innerHTML = ''
    instance = null
}
